package Javaa.Base;
//create an example of using HashMap class adding, accessing, and iterating key-value pairs
import java.util.HashMap;
import java.util.Map;
public class HashMapExample {
    public static void main(String[] args) {
        // Create a HashMap to store String keys and Integer values
        Map<String, Integer> ageMap = new HashMap<>();

        // Add key-value pairs to the HashMap
        ageMap.put("Alice", 30);
        ageMap.put("Bob", 25);
        ageMap.put("Charlie", 35);

        // Access a value using its key
        System.out.println("Alice's age: " + ageMap.get("Alice"));

        // Iterate through the HashMap and print all key-value pairs
        System.out.println("All entries in the age map:");
        for (Map.Entry<String, Integer> entry : ageMap.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }

        // Remove a key-value pair from the HashMap
        ageMap.remove("Bob");
        System.out.println("After removing Bob: " + ageMap);
    }
}